
if (NOT DEFINED CMAKE_HOST_SYSTEM_NAME OR NOT DEFINED CMAKE_HOST_SYSTEM_PROCESSOR)
  # find out on which system cmake runs
  if (CMAKE_HOST_UNIX)
    find_program(CMAKE_UNAME uname /bin /usr/bin /usr/local/bin )
    if (CMAKE_UNAME)
      if (NOT DEFINED CMAKE_HOST_SYSTEM_NAME)
        exec_program(uname ARGS -s OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_NAME)
      endif()
      if (NOT DEFINED CMAKE_HOST_SYSTEM_VERSION)
        exec_program(uname ARGS -r OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_VERSION)
      endif()
      if (NOT DEFINED CMAKE_HOST_SYSTEM_PROCESSOR)
        if (CMAKE_HOST_SYSTEM_NAME MATCHES "Linux|CYGWIN.*|Darwin|^GNU$")
          exec_program(uname ARGS -m OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_PROCESSOR RETURN_VALUE val)
          if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin" AND CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "Power Macintosh")
            # OS X ppc 'uname -m' may report 'Power Macintosh' instead of 'powerpc'
            set(CMAKE_HOST_SYSTEM_PROCESSOR "powerpc")
          endif()
        elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "OpenBSD")
          exec_program(arch ARGS -s OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_PROCESSOR RETURN_VALUE val)
        else()
          exec_program(uname ARGS -p OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_PROCESSOR RETURN_VALUE val)
          if ("${val}" GREATER 0)
            exec_program(uname ARGS -m OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_PROCESSOR RETURN_VALUE val)
          endif()
        endif()
        # check the return of the last uname -m or -p
        if ("${val}" GREATER 0)
          set(CMAKE_HOST_SYSTEM_PROCESSOR "unknown")
        endif()
        #set(CMAKE_UNAME ${CMAKE_UNAME} CACHE INTERNAL "uname command")
        # processor may have double quote in the name, and that needs to be removed
        string(REPLACE "\"" "" CMAKE_HOST_SYSTEM_PROCESSOR "${CMAKE_HOST_SYSTEM_PROCESSOR}")
        string(REPLACE "/" "_" CMAKE_HOST_SYSTEM_PROCESSOR "${CMAKE_HOST_SYSTEM_PROCESSOR}")
      endif()
    endif()
  else()
    if (CMAKE_HOST_WIN32)
      if (NOT DEFINED CMAKE_HOST_SYSTEM_NAME)
        set(CMAKE_HOST_SYSTEM_NAME "Windows")
      endif()
      if (NOT DEFINED CMAKE_HOST_SYSTEM_PROCESSOR)
        if (DEFINED ENV{PROCESSOR_ARCHITEW6432})
          set(CMAKE_HOST_SYSTEM_PROCESSOR "$ENV{PROCESSOR_ARCHITEW6432}")
        else()
          set(CMAKE_HOST_SYSTEM_PROCESSOR "$ENV{PROCESSOR_ARCHITECTURE}")
        endif()
      endif()
    endif()
  endif()
endif()
